package org.example.netty.test.nio.netty.chat.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.example.netty.test.nio.netty.chat.bean.JoinGroupMessage;
import org.example.netty.test.nio.netty.chat.bean.JoinUserMessage;
import org.example.netty.test.nio.netty.chat.bean.SystemMessage;
import org.example.netty.test.nio.netty.chat.common.SystemMessageType;
import org.example.netty.test.nio.netty.chat.session.GlobalContent;
import org.example.netty.test.nio.netty.chat.session.UserSession;
import org.example.netty.test.nio.netty.chat.util.NettyChannelUtil;

/**
 * @author zp
 * @version 1.0
 * @description: 处理消息JoinUserMessage
 * @date 2023/4/6 18:29
 */
@Slf4j
public class JoinUserMessageHandler extends SimpleChannelInboundHandler<JoinUserMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, JoinUserMessage msg) throws Exception {
        log.debug("加入私聊的消息：{}",msg);
        GlobalContent globalContent = GlobalContent.getInstance();
        // 加入私聊 加入双方的Session当中
        globalContent.addUserChat(msg);
        ctx.channel().writeAndFlush(msg);
    }
}
